const Path = require('path');
const Webpack = require("webpack");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');

module.exports = {
    //entry: './src/index.js',
    entry: {  //多入口
        index: './src/index.js',
        print: './src/print.js'
    },
    output: {
        //filename: 'bundle.js',
        filename: '[name].bundle.js',
        path: Path.resolve(__dirname, 'dist')
    },
    devtool: 'source-map',  //使用 source map
    devServer: {  //自刷新测试服务器
        contentBase: './dist'
    },
    plugins: [
        //开启清理
        // new CleanWebpackPlugin(['dist']),
        //开启压缩
        new Webpack.optimize.UglifyJsPlugin({
            sourceMap: true,
            compress: {
                warnings: false
            }
        }),
        //HTML重新构建
        new HtmlWebpackPlugin({
            title: 'Title'
        })
    ],
    module: {
        rules: [
            {  //CSS加载器
                test: /\.css$/,
                use: [
                    'style-loader',
                    'css-loader'
                ]
            },
            {  //图片加载器
                test: /\.(png|svg|jpg|gif)$/,
                use: [
                    'file-loader'
                ]
            },
            {  //字体加载器
                test: /\.(woff|woff2|eot|ttf|otf)$/,
                use: [
                    'file-loader'
                ]
            },
            {  //CSV加载器
                test: /\.(csv|tsv)$/,
                use: [
                    'csv-loader'
                ]
            },
            {  //XML加载器
                test: /\.(xml)$/,
                use: [
                    'xml-loader'
                ]
            },
        ]
    }
};